import net from '../../utils/net.js'
import { inputgetName } from '../../utils/inputBothBind.js'

Page({
  data: {
    stepText: ["1.卡号信息", "2.安全码", "3.信用卡有效期"],
    tel:'',
    bill:'',
    repay:'',
    step2Data:null
  },
  inputgetName: inputgetName,
  selectBill:function() {
    // TODO
    console.log("选择账单日")
  },
  selectRepay:function() {
    // TODO
    console.log("选择还款日")
  },
  toConfirm:function() {
    if (!this.data.tel || !this.data.bill || !this.data.repay) {
      wx.showToast({
        title: '请填写完整',
        icon: 'none'
      })
      return
    }
    net.http({
      url:'/api/index/index?method=add_credit',
      data: {
        bank_id: this.data.step2Data.id,
        bank_card: this.data.step2Data.cardNum,
        bank_tel: this.data.tel,
        cvn2: this.data.step2Data.cvn2,
        effective: this.data.step2Data.validDt,
        bill: this.data.bill,
        repayment: this.data.repay,
      },
      isShowLoading:true,
      successCb:this.sucCb
    })
  },
  sucCb:function(res) {
    wx.showToast({
      title: res.msg,
      icon: 'success'
    })
    setTimeout(function() {
      wx.navigateBack({
        delta: 3,
      })
    }, 500)
  },
  onLoad:function(options) {
    console.log(options)
    this.setData({
      step2Data: options
    })
  }
})